﻿using Client.Constant;
using Client.Framework.Message;
using Client.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Message.Response
{
    [MessageAttr(MessageId.MENU_LIST)]
    class MenuListResp : ResponseBaseMessage
    {
        public List<ViewMenu> Menus { get; } = new List<ViewMenu>();
        public int Count { get; set; }

        public override void Deserialize(byte[] buffer)
        {
            MenuList msg = MenuList.Parser.ParseFrom(buffer);
            foreach (var menu in msg.Menus)
            {
                ViewMenu viewMenu = new ViewMenu
                {
                    ID = menu.Id,
                    ParentId = menu.ParentId,
                    Icon = menu.Icon,
                    ScreenCode = menu.ScreenCode,
                    MenuName = menu.MenuName,
                    MenuType = menu.MenuType,
                    Sort = menu.Sort,
                    Status = (Enum.DataStatus)menu.Status,
                    Creator = menu.Creator,
                    CreateTime = menu.CreateTime,
                    Updator = menu.Updator,
                    UpdateTime = menu.UpdateTime
                };
                Menus.Add(viewMenu);
            }
            Count = msg.Count;
        }
    }
}
